import { PROCESS_STATUS_MAP } from '@/tools/common.js'
import { formatMenu } from '../utils/index'
export function columnListFilling() {
  return [
    {
      title: '所属菜单',
      key: 'formMenu',
      align: 'center',
      // minWidth: 300,
      render: (h, params) => {
        return h('Tooltip',
          {
            props: {
              transfer: true,
              maxWidth: '1000',
              content: formatMenu(this.menuList, params.row.formMenu),
              trigger: 'hover'
            }
          },
          [
            h('div', formatMenu(this.menuList, params.row.formMenu) || '-')
          ]
        )
      }
    },
    {
      title: '表单名称',
      key: 'areaname',
      align: 'center',
      minWidth: 300
    },
    {
      title: '单位名称',
      key: 'buname',
      minWidth: 200
    },
    {
      title: '填报周期',
      key: 'period',
      minWidth: 100
    },
    {
      title: '填报状态',
      key: 'status',
      minWidth: 100
    }
  ]
}

// 已审批
export function columnListProcessed() {
  return [
    {
      title: '表单名称',
      key: 'todoType',
      minWidth: 300
    },
    {
      title: '单位名称',
      minWidth: 200,
      render: (h, params) => {
        const regex = /^[a-zA-Z]/
        if (!regex.test(params.row.trgNode)) {
          return h('span', params.row.trgNode)
        } else {
          const item = this.$store.state.buList.filter(item => item.key === params.row.trgNode)[0]
          return h('span', item.value)
        }
      }
    },
    {
      title: '标题',
      key: 'wfTittle',
      minWidth: 400
    },
    {
      title: '发起人',
      key: 'submitterName'
    },
    {
      title: '发起时间',
      key: 'submitDate',
      minWidth: 160
    },
    {
      title: '审批人',
      key: 'approverList',
      render: (h, params) => {
        return h('span', params.row.approverName || params.row.approverList)
      }
    },
    {
      title: '审批结果',
      key: 'operateStatus',
      minWidth: 100,
      render: (h, params) => {
        return h('span', PROCESS_STATUS_MAP[params.row.operateStatus] || '')
      }
    },
    {
      title: '审批时间',
      key: 'approveDate',
      minWidth: 160
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 60,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '查看',
                handle: () => {
                  this.goProcessPage(params.row.bindId)
                }
              }
            ]
          }
        })
      }
    }
  ]
}

// 未审批
export function columnListUnhandled() {
  return [
    {
      title: '表单名称',
      key: 'todoType',
      minWidth: 300
    },
    {
      title: '单位名称',
      key: 'trgNode',
      minWidth: 200,
      render: (h, params) => {
        const regex = /^[a-zA-Z]/
        if (!regex.test(params.row.trgNode)) {
          return h('span', params.row.trgNode)
        } else {
          const item = this.$store.state.buList.filter(item => item.key === params.row.trgNode)[0]
          return h('span', item.value)
        }
      }
    },
    {
      title: '标题',
      key: 'wfTittle',
      minWidth: 400
    },
    {
      title: '发起人',
      key: 'submitterName'
    },
    {
      title: '发起时间',
      key: 'submitDate',
      minWidth: 160
    },
    {
      title: '当前处理人',
      key: 'approverList',
      render: (h, params) => {
        return h('span', params.row.approverName || params.row.approverList)
      }
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 60,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '查看',
                handle: () => {
                  this.goProcessPage(params.row.bindId)
                }
              }
            ]
          }
        })
      }
    }
  ]
}

// 表单中心未审批
export function columnFormCenterUnhandled() {
  return [
    {
      title: '所属菜单',
      key: 'formMenu',
      minWidth: 300,
      render: (h, params) => {
        return h('Tooltip',
          {
            props: {
              transfer: true,
              maxWidth: '1000',
              content: formatMenu(this.menuList, params.row.formMenu),
              trigger: 'hover'
            }
          },
          [
            h('div', formatMenu(this.menuList, params.row.formMenu) || '-')
          ]
        )
      }
    },
    {
      title: '表单名称',
      key: 'formName',
      align: 'center',
      minWidth: 300
    },
    {
      title: '单位名称',
      key: 'org',
      minWidth: 200,
      render: (h, params) => {
        const item = this.$store.state.buList.filter(item => item.key === params.row.org)[0]
        return h('span', item?.value || '--')
        // const regex = /^[a-zA-Z]/
        // if (!regex.test(params.row.trgNode)) {
        //   return h('span', params.row.trgNode)
        // } else {
        //   const item = this.$store.state.buList.filter(item => item.key === params.row.trgNode)[0]
        //   return h('span', item.value)
        // }
      }
    },
    {
      title: '标题',
      key: 'title',
      align: 'center',
    },
    {
      title: '发起人',
      key: 'formCreator',
      align: 'center',
    },
    {
      title: '发起时间',
      key: 'beginTime',
      minWidth: 160,
      align: 'center',
    },
    {
      title: '当前处理人',
      key: 'targetName',
      align: 'center',
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 60,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '查看',
                handle: () => {
                  this.goProcessPage(params.row.processId)
                }
              }
            ]
          }
        })
      }
    }
  ]
}

// 表单中心已审批
export function columnFormCenterProcessed() {
  return [
    {
      title: '所属菜单',
      key: 'formMenu',
      minWidth: 300,
      render: (h, params) => {
        return h('Tooltip',
          {
            props: {
              transfer: true,
              maxWidth: '1000',
              content: formatMenu(this.menuList, params.row.formMenu),
              trigger: 'hover'
            }
          },
          [
            h('div', formatMenu(this.menuList, params.row.formMenu) || '-')
          ]
        )
      }
    },
    {
      title: '表单名称',
      key: 'formName',
      align: 'center',
      minWidth: 300
    },
    {
      title: '单位名称',
      minWidth: 200,
      key: 'org',
      render: (h, params) => {
        const item = this.$store.state.buList.filter(item => item.key === params.row.org)[0]
        return h('span', item?.value || '--')
      }
    },
    {
      title: '标题',
      key: 'title',
      align: 'center',
    },
    {
      title: '发起人',
      key: 'formCreator',
      align: 'center',
    },
    {
      title: '发起时间',
      key: 'beginTime',
      minWidth: 160,
      align: 'center',
    },
    {
      title: '审批人',
      key: 'targetName',
      align: 'center',
    },
    {
      title: '审批结果',
      key: 'todoState',
      align: 'center',
      minWidth: 100,
      render: (h, params) => {
        return h('span', params.row.approvalState === 0 ? '待审核' : '审核通过')
      }
    },
    {
      title: '审批时间',
      key: 'endTime',
      align: 'center',
      minWidth: 160
    },
    {
      title: '操作',
      align: 'left',
      fixed: 'right',
      width: 60,
      render: (h, params) => {
        return h('RowTools', {
          props: {
            data: [
              {
                type: 'text',
                text: '查看',
                handle: () => {
                  this.goProcessPage(params.row.processId)
                }
              }
            ]
          }
        })
      }
    }
  ]
}
